#ifndef XMLPARSER_H
#define XMLPARSER_H

#include <QXmlStreamReader>
#include <QVector>
#include <QHash>
#include <QMap>
#include <QStringList>
#include <QFile>

struct AttributeProperties
{
    explicit AttributeProperties(
        const QString& rInitialValue,
        const QString& rAccess,
        const QString& rPoll):
    m_InitialValue(rInitialValue),
    m_Access(rAccess),
    m_Poll(rPoll)
    {
    }

    QString m_InitialValue;
    QString m_Access;
    QString m_Poll;
};

class XmlParser
{
public:

    typedef QHash<QString, QMap<QString, AttributeProperties> > PanelData_t;
    typedef QVector<PanelData_t> PanelDataList_t;

    explicit XmlParser();

    const PanelDataList_t& PanelDataList()
    {
        return m_PanelDataList;
    }

    const QStringList& PanelIDs()
    {
        return m_PanelIDs;
    }

    void ParseFile(QFile& rFile);

private:

    /**
     * @brief Reset_
     *
     * Reset the parser to the initial state
     */
    void Reset_();

    void ParsePanel_();
    void ParseEquipmentItem_();
    void ParseInfoItem_(const QString& GSOID);

    /**
     * @brief m_PanelDataList
     *
     * Every element of the Vector corresponds to a single Panel
     * Every Hash corresponds to a single Static GSOID
     * Every Map corresponds to an AttributeIDs vs their Initial Values , ie.:
     *
     * Panel#1 == Hash
     *      Key GSOID#1 == Map
     *          Key AttributeID#1 Value Pair(InitialValue#1, Access#1, Poll#1)
     *          Key AttributeID#2 Value Pair(InitialValue#2, Access#2, Poll#2)
     *      Key GSOID#2 == Map
     *          Key AttributeID#1 Value Pair(InitialValue#1, Access#1, Poll#1)
     *          Key AttributeID#2 Value Pair(InitialValue#2, Access#2, Poll#2)
     * Panel#2 == Hash
     *      Key GSOID#1 == Map
     *          Key AttributeID#1 Value Pair(InitialValue#1, Access#1, Poll#1)
     *          Key AttributeID#2 Value Pair(InitialValue#2, Access#2, Poll#2)
     *      Key GSOID#2 == Map
     *          Key AttributeID#1 Value Pair(InitialValue#1, Access#1, Poll#1)
     *          Key AttributeID#2 Value Pair(InitialValue#2, Access#2, Poll#2)
     *
     */
    PanelDataList_t m_PanelDataList;

    /**
     * @brief m_PanelIDs
     *
     * A list holding the names of the panels
     */
    QStringList m_PanelIDs;

    /**
     * @brief m_CurrentPanelIndex
     *
     * Keeps the index of the current xml Panel data that is being parsed
     */
    int m_CurrentPanelIndex;

    /**
     * @brief m_Xml
     *
     * Stream reader associated with the current file being parsed
     */
    QXmlStreamReader m_Xml;
};

#endif // XMLPARSER_H
